const api = require('../config/api.js')


/**
 * 上报日志
 * @param {string} options url 请求路径
 * @param {object} options data={url,appName,level,message,param,token,requestMethod} 上报请求数据  level: INFO  DEBUG WARN ERROR 
 * @param {string} options requestMethod  默认POST
 * @param {*} options 其他参数
 */
function reportParams(options) {
   // 请求时间
   const time =new Date( +new Date() + 8 * 3600 * 1000 ).toJSON().substr(0,19).replace("T"," ");
   const {
      url = '',
      data = { },
      requestMethod,
      ...otherProps
    } = options || {}

   const content_type = 'application/json'
   let header = { 'Content-Type': content_type }
   const params = {
      logData: JSON.stringify({
         ...data,
         time,
      })
   };
  wx.request({
     url: url || api.receiveLog,
     data: params,
     method:  requestMethod || 'POST',
     header: header,
     ...otherProps
  })
}

module.exports = {
  reportParams: reportParams,
}